//
//  WEXEmoticonButton.swift
//  microBlog
//
//  Created by apple on 16/4/28.
//  Copyright © 2016年 Hill. All rights reserved.
//

import UIKit

class WEXEmoticonButton: UIButton {

    var emoticon: WEXEmoticonModel? {
        
        didSet{
            
            guard let _ = emoticon else{
                
                return
            }
//            是emoji表情
            if emoticon?.type == "1" {
//                因为emoji表情是字符串，所以设置title 干掉图片
                self.setTitle(((emoticon?.code)! as NSString).emoji(), forState: UIControlState.Normal)
                self.setImage(nil, forState: UIControlState.Normal)
                
            }else{
//                图片表情
//                print("\(emoticon?.folderName ?? "")/\(emoticon?.png ?? "")")
                let image = UIImage(named: "\(emoticon?.folderName ?? "")/\(emoticon?.png ?? "")",inBundle: WEXEmoticonKeyBoardViewModel.sharedViewModel.emoticonBundle,compatibleWithTraitCollection: nil )
                
//                print(image)
                self.setImage(image, forState: UIControlState.Normal)
                
                self.setTitle(nil, forState: UIControlState.Normal)
                
            }
        }
    }

}
